package com.twu.bibilioteca;

import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: dixithk
 * Date: 6/20/14
 * Time: 10:59 AM
 * To change this template use File | Settings | File Templates.
 */
public class Login implements MenuOperations {

    UserInterface ui = new UserInterfaceApp();
    Library lib = new Library();

    public Login(UserInterface Ui, Library lib)
    {
        this.ui = Ui;
        this.lib = lib;

    }


    @Override
    public Result action() {

        ArrayList<String> credentials = ui.TakeInputFromUserFromLogin();
        User user =lib.getUser(credentials.get(0));
        if(user != null && user.getPassword().equals(credentials.get(1)))
        {
                 PresentUsers.signUp(user);
                return new Result("Logged in Successfully ! Enjoy the Services " , true) ;

        }
        else
        {
            return new Result("Login Failed !!!!", false) ;
        }



    }

    @Override
    public String getName() {
        return "LOG IN";  //To change body of implemented methods use File | Settings | File Templates.
    }
}
